#include<bits/stdc++.h>

#define rp(i,a,b) for(int i=a;i<b;++i)
#define rrp(i,b,a) for(int i=b;i>=a;--i)

using namespace std;

int days[12] = {31,28,31,30,31,30,31,31,30,31,30,31};

int isrunnian(int num){
	if(num%4 == 0 && num%100 != 0)return 1;
	if(num%400 == 0) return 1;
	return 0;
}

int main(){
	int y,d;cin>>y>>d;
	rp(i , 0 , 12){
		int tmp = d;
		tmp-=days[i];
		if(i == 2 && isrunnian(y)){
			tmp-=1;
		}
		if(tmp <= 0){
			printf("%d\n%d\n", i+1, d);
			break;
		}
		d = tmp;
	}
	
	return 0;
}